4. 3D Solid Mechanics#

The equations of elasticity describe the deformation of solids due to applied forces.

from netgen.occ import *
from ngsolve.webgui import Draw
import ngsolve
box = Box((0,0,0), (3,0.6,1))
box.faces.name="outer"
cyl = sum( [Cylinder((0.5+i,0,0.5), Y, 0.25,0.8) for i in range(3)] )
cyl.faces.name="cyl"
geo = box-cyl

Draw(geo);

find edges between box and cylinder, and build chamfers (requires OCC 7.4 or newer):

cylboxedges = geo.faces["outer"].edges * geo.faces["cyl"].edges
cylboxedges.name = "cylbox"
geo = geo.MakeChamfer(cylboxedges, 0.03)

name faces for boundary conditions:

geo.faces.Min(X).name = "fix"
geo.faces.Max(X).name = "force"

Draw(geo);
from ngsolve import *
from ngsolve.webgui import Draw
mesh = Mesh(OCCGeometry(geo).GenerateMesh(maxh=0.1)).Curve(3)
Draw (mesh);

4.1. Linear elasticity#

Displacement: \(u : \Omega \rightarrow R^3\)

Linear strain: $\( \varepsilon(u) := \tfrac{1}{2} ( \nabla u + (\nabla u)^T ) \)$

Stress by Hooke’s law: $\( \sigma = 2 \mu \varepsilon + \lambda \operatorname{tr} \varepsilon I \)$

Equilibrium of forces: $\( \operatorname{div} \sigma = f \)$

Displacement boundary conditions: $\( u = u_D \qquad \text{on} \, \Gamma_D \)$

Traction boundary conditions: $\( \sigma n = g \qquad \text{on} \, \Gamma_N \)$

4.2. Variational formulation:#

Find: \(u \in H^1(\Omega)^3\) such that \(u = u_D\) on \(\Gamma_D\) $\( \int_\Omega \sigma(\varepsilon(u)) : \varepsilon(v) \, dx = \int_\Omega f v dx + \int_{\Gamma_N} g v ds \)\( holds for all \)v = 0\( on \)\Gamma_D$.

E, nu = 210, 0.2
mu  = E / 2 / (1+nu)
lam = E * nu / ((1+nu)*(1-2*nu))

def Stress(strain):
    return 2*mu*strain + lam*Trace(strain)*Id(3)    
fes = VectorH1(mesh, order=3, dirichlet="fix")
u,v = fes.TnT()
gfu = GridFunction(fes)

with TaskManager():
    a = BilinearForm(InnerProduct(Stress(Sym(Grad(u))), Sym(Grad(v))).Compile()*dx)
    pre = Preconditioner(a, "bddc")
    a.Assemble()
force = CF( (1e-3,0,0) )
f = LinearForm(force*v*ds("force")).Assemble()
from ngsolve.krylovspace import CGSolver
inv = CGSolver(a.mat, pre, printrates='\r', tol=1e-8)
gfu.vec.data = inv * f.vec
CG iteration 1, residual = 0.00018071481331954998     
CG iteration 2, residual = 7.786988796915335e-05     
CG iteration 3, residual = 8.498290164433083e-05     
CG iteration 4, residual = 6.815633040170489e-05     
CG iteration 5, residual = 6.117753826924984e-05     
CG iteration 6, residual = 4.64977050442093e-05     
CG iteration 7, residual = 3.3107797304022026e-05     
CG iteration 8, residual = 2.734452092395876e-05     
CG iteration 9, residual = 2.0649562682631962e-05     
CG iteration 10, residual = 1.6898694209669377e-05     
CG iteration 11, residual = 1.1676177837590706e-05     
CG iteration 12, residual = 8.71792124006097e-06     
CG iteration 13, residual = 6.578387898741824e-06     
CG iteration 14, residual = 5.1537494667802215e-06     
CG iteration 15, residual = 3.6889549037402206e-06     
CG iteration 16, residual = 3.0209233346364892e-06     
CG iteration 17, residual = 2.235745334989845e-06     
CG iteration 18, residual = 1.6042952744389696e-06     
CG iteration 19, residual = 1.1956102419097958e-06     
CG iteration 20, residual = 8.396604190595138e-07     
CG iteration 21, residual = 6.626002655212835e-07     
CG iteration 22, residual = 4.736141802281869e-07     
CG iteration 23, residual = 3.6535329314710644e-07     
CG iteration 24, residual = 2.539853681559479e-07     
CG iteration 25, residual = 2.0630254971094196e-07     
CG iteration 26, residual = 1.39343130824201e-07     
CG iteration 27, residual = 1.1178640612423638e-07     
CG iteration 28, residual = 7.469243140049771e-08     
CG iteration 29, residual = 5.519225747739925e-08     
CG iteration 30, residual = 4.0806859508922416e-08     
CG iteration 31, residual = 2.6842187937726432e-08     
CG iteration 32, residual = 2.249071906138888e-08     
CG iteration 33, residual = 1.5197915669301024e-08     
CG iteration 34, residual = 1.0348799497740701e-08     
CG iteration 35, residual = 8.437759161411955e-09     
CG iteration 36, residual = 5.2954361468793475e-09     
CG iteration 37, residual = 4.01067745558318e-09     
CG iteration 38, residual = 2.507510977470233e-09     
CG iteration 39, residual = 1.793154705463741e-09     
CG iteration 40, residual = 1.4657433561819093e-09     
CG iteration 41, residual = 1.2619771607734457e-09     
CG iteration 42, residual = 9.480900007560852e-10     
CG iteration 43, residual = 5.768038387555466e-10     
CG iteration 44, residual = 4.059106432327829e-10     
CG iteration 45, residual = 2.9337276765472637e-10     
CG iteration 46, residual = 2.3997040375776197e-10     
CG iteration 47, residual = 2.1711167308700688e-10     
CG iteration 48, residual = 1.3720126205750998e-10     
CG iteration 49, residual = 9.021256864627364e-11     
CG iteration 50, residual = 6.743662525431681e-11     
CG iteration 51, residual = 4.406745477732711e-11     
CG iteration 52, residual = 3.000841210617216e-11     
CG iteration 53, residual = 2.0400023667096293e-11     
CG iteration 54, residual = 1.4811867199339794e-11     
CG iteration 55, residual = 1.0517721174558358e-11     
CG iteration 56, residual = 8.057981287019116e-12     
CG iteration 57, residual = 6.866162517571396e-12     
CG iteration 58, residual = 4.751040007737012e-12     
CG iteration 59, residual = 2.9215331423480864e-12     
CG iteration 60, residual = 2.054580399544891e-12     
CG iteration 61, residual = 1.3942092567505084e-12     
CG converged in 61 iterations to residual 1.3942092567505084e-12
with TaskManager():
    fesstress = MatrixValued(H1(mesh,order=3), symmetric=True)
    gfstress = GridFunction(fesstress)
    gfstress.Interpolate (Stress(Sym(Grad(gfu))))
Draw (5e4*gfu, mesh);
Draw (Norm(gfstress), mesh, deformation=1e4*gfu, draw_vol=False, order=3);